package com.liml.demo0319.basic.io;

import java.io.File;
import java.io.FilenameFilter;
import java.util.Arrays;
import java.util.regex.Pattern;

/**
 *
 * @author Administrator
 */
public class DirList {
    public static void main(String[] args) {
        File path = new File(".\\src\\main\\java\\com\\liml\\demo0319\\basic\\io");

        //E:\IdeaProjects\demo0319\src\main\java\com\liml\demo0319\basic\io
//        File path = new File("E:\\IdeaProjects\\demo0319\\src\\main\\java\\com\\liml\\demo0319\\basic\\io");

        String[] list;
        if (args.length == 0) {
            list = path.list();
        } else {
            list = path.list(new DirFilter(args[0]));
        }
        Arrays.sort(list, String.CASE_INSENSITIVE_ORDER);
        for (String dirItem : list) {
            System.out.println("dirItem = " + dirItem);
        }
    }
}

class DirFilter implements FilenameFilter {
    private Pattern pattern;

    public DirFilter(String regex) {

        pattern = Pattern.compile(regex);
    }

    @Override
    public boolean accept(File dir, String name) {

        return pattern.matcher(name).matches();
    }
}